package com.gy.edu.teach.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.gy.edu.R;
import com.gy.edu.util.ListViewItemListener;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者：gy on 16/12/23
 * 说明：
 */
public class TeachHomeAdapter extends BaseAdapter {

    private Context context;
    private ListViewItemListener listener;
    private List<Integer> selects;
    private int isSelectALl;//1为全选
    private int isEdit;//是否为编辑状态

    public TeachHomeAdapter(Context context){
        this.context = context;
        selects = new ArrayList<>();
    }

    /** 设置是否全选*/
    public void setIsSelectALl(int isSelectALl){
        this.isSelectALl = isSelectALl;
        if(isSelectALl == 0){
            selects.clear();
        }
        this.notifyDataSetChanged();
    }

    /** 设置选装条目*/
    public void setSelects(List<Integer> selects){
        this.selects = selects;
        notifyDataSetChanged();
    }

    /** 设置选中状态*/
    public void setIsEdit(int isEdit){
        this.isEdit = isEdit;
        if(isEdit == 0){
            selects.clear();
            notifyDataSetChanged();
        }
    }

    @Override
    public int getCount() {
        return 3;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView == null){
            convertView = View.inflate(context, R.layout.adapter_teach_home,null);
        }
        ImageView imgSelect = (ImageView) convertView.findViewById(R.id.adapter_teach_home_img_select);
        TextView tvTitle = (TextView) convertView.findViewById(R.id.adapter_teach_home_tv_title);
        TextView tvNumber = (TextView) convertView.findViewById(R.id.adapter_teach_home_tv_number);
        TextView tvSize = (TextView) convertView.findViewById(R.id.adapter_teach_home_tv_size);
        if(isEdit == 0){
            imgSelect.setVisibility(View.GONE);
        } else {
            imgSelect.setVisibility(View.VISIBLE);
            if(isSelectALl == 1){//如果全选
                imgSelect.setImageResource(R.mipmap.del_choose);
            } else {
                if(selects.contains(position)){
                    imgSelect.setImageResource(R.mipmap.del_choose);
                } else {
                    imgSelect.setImageResource(R.mipmap.del_unchoose);
                }
            }
        }

        if(position == 0){
            tvTitle.setText("汽车电器构造与维修");
            tvNumber.setText("2");
            tvSize.setText("1.31M");
        } else if(position == 1){
            tvTitle.setText("汽车发动机构造与维修");
            tvNumber.setText("2");
            tvSize.setText("6.21M");
        } else if(position == 2){
            tvTitle.setText("汽车维护保养");
            tvNumber.setText("1");
            tvSize.setText("2.43M");
        }

        return convertView;
    }
}
